package com.lkbaby.flowable;

import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/test")
public class MyProcess {

	@Autowired
	private RepositoryService repositoryService;

	@Autowired
	private RuntimeService runtimeService;

	@Autowired
	private TaskService taskService;

	/**
	 * 流程部署
	 *
	 * @throws Exception
	 */
	@RequestMapping("/deploy")
	public void testDeploy() {
		Deployment deploy = repositoryService.createDeployment()
				.addClasspathResource("processes/信号边界事件.bpmn20.xml")
				.name("信号边界事件")
				.deploy();
		System.out.println("deploy.getId() = " + deploy.getId());
		System.out.println("deploy.getName() = " + deploy.getName());
		System.out.println("部署开始的时间：" + new Date());
		//TimeUnit.MINUTES.sleep(3);
	}

	/**
	 * 启动流程
	 *
	 * @throws Exception
	 */
	@RequestMapping("/startFlow")
	public void startFlow() {
		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("event2004");
	}

	/**
	 * 通过信号发送来触发信号启动事件的执行
	 * 全局的信息
	 *
	 * @throws Exception
	 */
	@RequestMapping("/signalReceived")
	public void signalReceived() {
		runtimeService.signalEventReceived("signal2");
	}

}
